import re

import requests

url = 'https://www.4399.com/'
response = requests.get(url)
html = response.content.decode('gb2312')
results1 = re.findall(
    r'<li><a  onclick=".*?return true;"  href="(/.*?)">.*?<img lzimg="1" lz_src="(.*?)" alt="(.*?)" />.*?</a></li>',
    html, re.S)
results2 = re.findall(r'<li><a  href="(.*?)">.*?<img lzimg="1" lz_src="(.*?)" alt="(.*?)" />.*?</a></li>', html, re.S)

results = results1 + results2
for result in results:
    img_url = 'https:' + result[1]
    title = result[2]
    img_response = requests.get(img_url)
    with open(f'../static/4399/img/{title}.jpg', 'wb') as f:
        f.write(img_response.content)
